import java.util.Arrays;

public class Main {
    public static void main(String[] args) {

    }
    //买股票最佳时间2
    public int maxProfit2(int[] prices) {
        if(prices.length <= 1){
            return 0;
        }
        int a = prices[0];
        int b = prices[1];
        int c = Math.max(0 , b - a);
        for(int i = 1; i < prices.length - 1; i++){
            a = prices[i];
            b = prices[i + 1];
            c = Math.max(c , c + b - a);
        }
        return c;
    }

    //买股票的最佳时间1
    public int maxProfit1(int[] prices) {
        int a = prices[0];
        int b = prices[0];
        int c = b - a;
        for(int i = 0; i < prices.length; i++){
            c = Math.max(c , b - a);
            a = Math.min(a , b);
            b = prices[i];
        }
        return Math.max(c , b - a);
    }
}